package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CaseDangerExposure;
import com.ruoyi.system.service.ICaseDangerExposureService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 危险因素Controller
 * 
 * @author ruoyi
 * @date 2022-04-03
 */
@Controller
@RequestMapping("/system/CaseDangerExposure")
public class CaseDangerExposureController extends BaseController
{
    private String prefix = "system/CaseDangerExposure";

    @Autowired
    private ICaseDangerExposureService caseDangerExposureService;

    @RequiresPermissions("system:CaseDangerExposure:view")
    @GetMapping()
    public String CaseDangerExposure()
    {
        return prefix + "/CaseDangerExposure";
    }

    /**
     * 查询危险因素列表
     */
    @RequiresPermissions("system:CaseDangerExposure:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CaseDangerExposure caseDangerExposure)
    {
        startPage();
        List<CaseDangerExposure> list = caseDangerExposureService.selectCaseDangerExposureList(caseDangerExposure);
        return getDataTable(list);
    }

    /**
     * 导出危险因素列表
     */
    @RequiresPermissions("system:CaseDangerExposure:export")
    @Log(title = "危险因素", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CaseDangerExposure caseDangerExposure)
    {
        List<CaseDangerExposure> list = caseDangerExposureService.selectCaseDangerExposureList(caseDangerExposure);
        ExcelUtil<CaseDangerExposure> util = new ExcelUtil<CaseDangerExposure>(CaseDangerExposure.class);
        return util.exportExcel(list, "危险因素数据");
    }

    /**
     * 新增危险因素
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存危险因素
     */
    @RequiresPermissions("system:CaseDangerExposure:add")
    @Log(title = "危险因素", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CaseDangerExposure caseDangerExposure)
    {
        return toAjax(caseDangerExposureService.insertCaseDangerExposure(caseDangerExposure));
    }

    /**
     * 修改危险因素
     */
    @RequiresPermissions("system:CaseDangerExposure:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CaseDangerExposure caseDangerExposure = caseDangerExposureService.selectCaseDangerExposureById(id);
        mmap.put("caseDangerExposure", caseDangerExposure);
        return prefix + "/edit";
    }

    /**
     * 修改保存危险因素
     */
    @RequiresPermissions("system:CaseDangerExposure:edit")
    @Log(title = "危险因素", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CaseDangerExposure caseDangerExposure)
    {
        return toAjax(caseDangerExposureService.updateCaseDangerExposure(caseDangerExposure));
    }

    /**
     * 删除危险因素
     */
    @RequiresPermissions("system:CaseDangerExposure:remove")
    @Log(title = "危险因素", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(caseDangerExposureService.deleteCaseDangerExposureByIds(ids));
    }
}
